//
//  CloseCell.m
//  Gunterapple
//
//  Created by 热带雨林 on 2020/3/18.
//  Copyright © 2020 热带雨林. All rights reserved.
//

#import "CloseCell.h"

@interface CloseCell()

@property (nonatomic, strong) UIView *bgView;//背景
@property (nonatomic, strong) UIImageView *iconImageView;
@property (nonatomic, strong) UILabel *titleLab;//内容
@property (nonatomic, strong) UIButton *typeBtn;//按钮

@end

@implementation CloseCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self  = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self initLayout];
    }
    return self;
}
#pragma mark -布局
- (void)initLayout{
    //通过设置contentView背景色的方式调用contentView的lazy方法
    self.contentView.backgroundColor = [UIColor clearColor];
    //用一个view将cell中的所有控件包起来
    self.bgView = [[UIView alloc]initWithFrame:CGRectMake(14, 0, 386, 115)];
    [self addSubview:self.bgView];
//    [self.contentView addSubview:self.bgView];
    self.bgView.backgroundColor = NormalColor;
    self.bgView.layer.cornerRadius = 10;
    self.bgView.clipsToBounds = YES;
    
//    UIImage *img = [UIImage imageNamed:@"closeImage"];
//    self.bgView.layer.contents = (id)img.CGImage;
    
//    self.bgImageView = [[UIImageView alloc]initWithFrame:self.bgView.bounds];
////    [self addSubview:self.bgImageView];
//    self.bgImageView.layer.cornerRadius = 10;
//    self.bgImageView.clipsToBounds = YES;
//    [self.bgImageView setImage:[UIImage imageNamed:@"closeImage"]];
//    [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.equalTo(self.bgView);
//        make.left.equalTo(self.bgView.mas_left);
//        make.right.equalTo(self.bgView.mas_right);
//        make.bottom.equalTo(self.bgView.mas_bottom);
//    }];
    //
    self.iconImageView = [[UIImageView alloc]initWithFrame:CGRectZero];
    self.iconImageView.backgroundColor = [UIColor redColor];
    self.iconImageView.layer.cornerRadius = 10.0f;
    self.iconImageView.layer.masksToBounds = YES;
    self.iconImageView.image = [UIImage imageNamed:@"armImg21-1"];
    self.iconImageView.contentMode = UIViewContentModeScaleAspectFill;
    self.iconImageView.clipsToBounds = YES;
    [self.bgView addSubview:self.iconImageView];
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(self.bgView).offset(10);
        make.size.mas_equalTo(CGSizeMake(90, 90));
    }];
    
    self.titleLab = [[UILabel alloc]initWithFrame:CGRectZero];
    self.titleLab.textColor = [UIColor whiteColor];
    [self.bgView addSubview:self.titleLab];
    self.titleLab.font = [UIFont fontWithName:Helvetica size:15];
    self.titleLab.numberOfLines = 0;
//    self.titleLab.textAlignment = NSTextAlignmentLeft;
    [self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(20);
        make.left.equalTo(self.iconImageView.mas_right).offset(5);
        make.width.mas_lessThanOrEqualTo(200);
    }];
    
    self.typeBtn = [[UIButton alloc]initWithFrame:CGRectZero];
    [self.typeBtn setImage:[UIImage imageNamed:@"btn_open"] forState:UIControlStateNormal];
    [self.bgView addSubview:self.typeBtn];
    
    [self.typeBtn addTarget:self action:@selector(openMemeryView:) forControlEvents:UIControlEventTouchUpInside];
    [self.typeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView).offset(5);
        make.right.equalTo(self.bgView.mas_right).offset(-20);
        make.width.height.mas_equalTo(34);
    }];
    
}

- (void)setModel:(openOrCloseModel *)model{
   self.titleLab.text = model.tipStr;
}
- (void)setView:(openOrCloseModel *)model{
     
}
#pragma mark - 点击打开
- (void)openMemeryView:(UIButton *)sender{
    
    //将打开的的cell记录到保存状态的数组中
    [self.indexArr addObject:[NSString stringWithFormat:@"%d", self.index]];
    
    if([self.delegate respondsToSelector:@selector(baseCell:withBtnType:withIndex:withArray:)]){
        [self.delegate baseCell:self
                    withBtnType:OPEN withIndex:self.index withArray:self.indexArr];
    }
}


- (void)awakeFromNib {
    [super awakeFromNib];
    
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
